package com.demo.las.repository;

import com.demo.las.entity.AffairCatalog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface AffairCatalogRepository extends JpaRepository<AffairCatalog, Long> {
    Optional<AffairCatalog> findByCode(String code);

    @Query("SELECT a FROM AffairCatalog a WHERE a.active = true ORDER BY a.categoryCode ASC, a.itemCode ASC")
    List<AffairCatalog> findAllActive();

    @Query("SELECT a FROM AffairCatalog a WHERE a.active = true AND a.categoryCode = :categoryCode ORDER BY a.itemCode ASC")
    List<AffairCatalog> findActiveByCategory(@Param("categoryCode") Integer categoryCode);
}